<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Test Result Report</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<style type="text/css">
body {font-size: 90%; }

h1 {
  font-size: 16pt;
  color: gray;
}

table {
  border-collapse: collapse;
  border: 1px solid #000;
}

td{
  border: 1px solid #777;
  padding: 1px;
}

dd {margin:0em 0em 0em 0.6em;}

.hidden {display: none;}
#stat_table {width:60%;}
#stat_table a{text-decoration: none;}
#result_table {width: 90%;}
.testcase_result {
    width: 100%;
    border-collapse: collapse;
    border: 0px none;
    float:left;
}
.details {
    padding: 1px;
    text-align: left;
}
.details pre {background-color: #E6E6D6;}
.results {background-color: #E6E6D6;}
.banner  {
    font-weight: bold;
    color: black;
    background-color: #bbb; 
}

.pass  { background-color: #BFEEA0; }
.fail  { background-color: #DDA098; }
.float {float:left;}

</style>
<script language="javascript" type="text/javascript">
function showSomeCase(class_name){
  var result_table = document.getElementById('result_table');
  var testcases = result_table.getElementsByTagName('tr');
  for (var i=0; i < testcases.length; i++){
    var testcase = testcases[i];
    if (testcase.id) {
      var className = testcase.className;
      if (className.indexOf(class_name) != -1) {
        testcase.className = className.replace(/hidden/, '');
      }
      else{
        testcase.className += ' hidden';
      }
    }
  }
}

function fold(){
  for (className in ("results", "desc", "env")) {
    var es = document.getElementsByClassName(className);
    for (var i=0; i < es.length; i++) {
      if (!es[i].className.match('hidden')) {
        es[i].className += ' hidden';
      }
    }
  }
}

function toggleDisplay(eid){
  var e = document.getElementById(eid);
  if (e.className.match('hidden')) {
    e.className = e.className.replace(/hidden/, '');
  }
  else {
    e.className += ' hidden';
  }
}

</script>
</head>

<body>
<h1>${description.get("title", "Selenium Test")}</h1>
<p>Start Time: ${description.get("time start", "Not ya")}</p>
<p>Stop Time :${description.get("time stop", "Not ya")}</p>
<p>Status: ${description.get("status", "")}</p>

<table id="stat_table">
  <tr class='banner'>
    <td>Test Group</td>
    <td>Count</td>
    <td>Pass</td>
    <td>Fail</td>
  </tr>
  % for result in results:
  <tr id="${result['name']}">
    <td>
      <a href="#${result['name']}">
        ${result['name']}
      </a>
    </td>
    <td>${result["fail"] + result["pass"]}</td>
    <td>${result["fail"]}</td>
    <td>${result["pass"]}</td>
  </tr>
  % endfor
  <tr class='banner'>
    <% pass_cnt = 0%>
    <% fail_cnt = 0%>
    % for result in results:
    <% pass_cnt += result['pass']%>
    <% fail_cnt += result['fail']%>
    % endfor
    <% total_cnt = pass_cnt + fail_cnt%>
    <td>Total</td>
    <td>${total_cnt}</td>
    <td>${pass_cnt}</td>
    <td>${fail_cnt}</td>
  </tr>
</table>

<dl>
  <dd class='float'>
    <a href="javascript:showSomeCase('pass')">Show Passed Only</a>
  </dd>
  <dd class='float'>
    <a href="javascript:showSomeCase('fail')">Show Failed Only</a>
  </dd>
  <dd class='float'>
    <a href="javascript:showSomeCase('')">Show All</a>
  </dd>
  <dd class='float'>
    <a href="javascript:fold()">Fold All</a>
  </dd>
</dl>

<table id='result_table'>
  % for result in results:
  <tr class="banner">
    <a name="${result['name']}">
      <td colspan="3">
         ${result['name']}
      </td>
    </a>
  </tr>
  % for case in result['cases']:
  <%
    passed = len(filter(lambda u: u.result, case.results))
    failed = len(case.results) - passed
  %>
  <tr id="case_${case.id}" class="${'pass' if failed == 0 else 'fail' }">
    <td align="left">
      <strong> ${case.name} </strong> has ${passed} passed and  ${failed} failed result
      <div>
        <a href="javascript:toggleDisplay('desc_${case.id}')"> show description</a>
        <a href="javascript:toggleDisplay('results_${case.id}')"> show results</a>
      </div>
      <pre id="desc_${case.id}" class="desc hidden">
        ${case.description or 'No Description'}
      </pre>
      <div id="results_${case.id}" class='results hidden'>
        <table width="100%" >
          <tr>
            <th>RESULT</th>
            <th>START</th>
            <th>STOP</th>
            <th>ARGUMENT</th>
          </tr>
          <tbody>
            % for case_result in case.results:
            <tr>
              <td class="${'pass' if case_result.result else 'fail'}">${'PASS' if case_result.result else 'FAIL'}</td>
              <td>${case_result.time_start}</td>
              <td>${case_result.time_stop}</td>
              <td>${case_result.args}</td>
            </tr>
            <% 
            message_list = dict()
            case_result.messages.sort(lambda x, y: cmp(x.order, y.order))
            for message in case_result.messages:
              if not message_list.has_key(message.order):
                message_list[message.order] = []
              message_list[message.order].append(message)
            %>
            % for messages in message_list.values():
            <tr>
              <td colspan="4">
                <div> 
                  % for message in messages:
                  <div> 
                    <a href="javascript:toggleDisplay('msg_env_${message.id}')">${message.msg}</a>
                    <pre id="msg_env_${message.id}" class="env hidden">${message.env}</pre>
                  </div>
                  % endfor
                </div>
              </td>
            </tr>
            % endfor
            % endfor
          </tbody>
        </table>
      </div>
    </td>
  </tr>
  % endfor
  % endfor
</table>
</body>
</html>